#include <stdlib.h>
#include <stdio.h>

#include "strops.h"
#include "intdefs.h"

int main() {

  /* storage for various bitstrings */
  char bits1[8+1] = { 0 };
  char bits2[8+1] = { 0 };
  char bits3[8+1] = { 0 };

  /* initialize a byte with all bits off */
  Byte byte1 = byte_static_init( MASK_OFF );

  /* initialize a byte with all bits on */
  Byte byte2 = byte_static_init( MASK_ON );

  /* initialize a byte with bits 3, 5 and 7 on */
  Byte byte3 = byte_static_init( (MASK3|MASK5|MASK7) );

  /* convert and print out a baseline for the tests */
  byte2str(byte1, bits1, BIN);
  byte2str(byte2, bits2, BIN);
  byte2str(byte3, bits3, BIN);
  printf("Baseline:  byte1=%s, byte2=%s, byte3=%s\n", bits1, bits2, bits3);


  /* Test: flip the zeroth bit in byte1 */
  bit_flip(&byte1, MASK0);
  byte2str(byte1, bits1, BIN);
  printf("flip zeroth byte1 test: %s\n", bits1);

  /* Test: flip the 3rd and 4th bits in byte2 */
  bit_flip(&byte2, (MASK3|MASK4));
  byte2str(byte2, bits2, BIN);
  printf("flip 3rd and 4th byte2 test: %s\n", bits2);

  /* Test: flip all the bits in byte2 */
  bit_all_flip(&byte2);
  byte2str(byte2, bits2, BIN);
  printf("flip all bits in byte2 test: %s\n", bits2);

  /* Test: Turn bits 3 and 7 off in byte3 */
  bit_off(&byte3, (MASK3|MASK7));
  byte2str(byte3, bits3, BIN);
  printf("turn off 3rd and 7th byte3 test: %s\n", bits3);

  /* Test: Turn all bits off in byte3 */
  bit_all_off(&byte3);
  byte2str(byte3, bits3, BIN);
  printf("turn all bits off byte3 test: %s\n", bits3);

  /* Test: Turn all bits on in byte3 */
  bit_all_on(&byte3);
  byte2str(byte3, bits3, BIN);
  printf("turn all bits on byte3 test: %s\n", bits3);

  /* Test: show return types can be masks */ 
  bit_all_off(&byte1);
  bit_on(&byte1, bit_off(&byte3, (MASK1|MASK2|MASK4)) );
  byte2str(byte1, bits1, BIN);
  printf("turn on all bits EXCEPT 1, 2 and 4 in byte1: %s\n", bits1);



  return(0);

}
